define(['ojs/ojcore', 'knockout', 'jquery','ojs/ojmodule', 'ojs/ojrouter','ojs/ojpagingcontrol'], function(oj, ko, $) {
    function servelistt() {
        var serveModule = {
        	flag:false,
        	selectedServe: ko.observable({
        		assetId:'001',
				ipAddress:'192.168.1.1',
				userName:'gy',
				password:'1234',
        	}),
        	servelist:ko.observableArray([
        			{
        				assetId:'001',
        				ipAddress:'192.168.1.1',
        				userName:'gy',
        				password:'1234',
        			},
        			{
        				assetId:'002',
        				ipAddress:'192.168.1.2',
        				userName:'gy',
        				password:'1234',
        			},
        			{
        				assetId:'003',
        				ipAddress:'192.168.1.3',
        				userName:'gy',
        				password:'1234',
        			},
        			{
        				assetId:'004',
        				ipAddress:'192.168.1.4',
        				userName:'gy',
        				password:'1234',
        			}
        		]),
        	searchServeList:function(){

        	},
        	checkall:function(){ 
        		if(this.flag){
        			$('.item_selected:checked').prop('checked',false);
        			this.flag = false;
        		}else{
        			$('.item_selected').prop('checked',true);
        			this.flag = true;
        		}
        		console.log($('.item_selected:checked'));
        	},
        	diagoClose:function(){
        		$('#serve_add').hide('fast');
        		$('#serve_change').hide('fast');
        		$('#mask').hide('fast');
        	},
        	addServe:function(){
        		$('#serve_add').show('fast');
        		$('#mask').show('fast');
        	},
        	serveAdd:function(){
        		$.ajax({
        			type:'get',
        			url:'',
        			data:{

        			},
        			success:function(data){
        				console.log(data);
        			}
        		})
        	},
        	changeServe:function(){
        		switch($('input:checked').length){
        			case 1: change(); break;
        			case 0: alert('请选择一个服务器'); break;
        			default : alert('修改时只能选择一个服务器操作'); 
        		}
        		function change(){
	        		$('#mask').show('fast')
	        		$('#serve_change').show('fast');
	        		var index = $('input:checked').index('.item_selected');
	        		var $curdom = $('.serve_item').eq(index).find('span');
	        		$('#cassetId').val($curdom[1].innerHTML);
	        		$('#cIPAddress').val($curdom[2].innerHTML);
	        		$('#cusername').val($curdom[3].innerHTML);
	        		$('#cpassword').val($curdom[4].innerHTML);
        		}
        	},
        	deleteServe:function(){
        		switch($('input:checked').length){
        			case 0: alert('请选择一个服务器'); break;
        			default : change(); 
        		}
        		function change(){
	        		$('#mask').show('fast')
	        		$('#serve_change').show('fast');
	        		var index = $('input:checked').index('.item_selected');
	        		var $curdom = $('.serve_item').eq(index).find('span');
	        		$('#cassetId').val($curdom[1].innerHTML);
	        		$('#cIPAddress').val($curdom[2].innerHTML);
	        		$('#cusername').val($curdom[3].innerHTML);
	        		$('#cpassword').val($curdom[4].innerHTML);
        		}
        	}
        };
        	console.log(11111);
        this.handleAttached =function(){
        	console.log('handleAttached');
            ko.cleanNode(document.getElementById('serve_list'));
        ko.applyBindings(serveModule,document.getElementById('serve_list'));
        }
    }
    // ko.applyBindings(homeViewModule, document.getElementsByClassName('content')[0]);
    return new servelistt();
});
